package elasticsearch

import (
	"easyShop/core/config"
	"github.com/olivere/elastic/v7"
)

var Client *elastic.Client

func GetConnect() (*elastic.Client, error) {
	//这个地方有个小坑 不加上elastic.SetSniff(false) 会连接不上
	var host = config.GetConfig("elasticsearch.host").(string)
	if Client == nil {
		var err error
		Client, err = elastic.NewClient(elastic.SetSniff(false), elastic.SetURL(host))
		if err != nil {
			return Client, err
		}
	}

	return Client, nil
}

func GetNewConnect() (*elastic.Client, error) {
	//这个地方有个小坑 不加上elastic.SetSniff(false) 会连接不上
	var host = config.GetConfig("elasticsearch.host").(string)
	Client, err := elastic.NewClient(elastic.SetSniff(false), elastic.SetURL(host))
	if err != nil {
		return Client, err
	}

	return Client, nil
}
